home *** CD-ROM | disk | FTP | other *** search
/ Gigarom 1 / Gigarom Macintosh Archives (Quantum Leap)(CDRM1080320)(1993).iso / FILES / DEV / I-Z / TransSkel.cpt / MSkelEdit.pas < prev    next >
Pascal/Delphi Source File  |  1987-01-07  |  3KB  |  177 lines

  1. {    TransSkel multiple-window demonstration: TextEdit module}
  2.  
  3. {    This module handles a simple TextEdit window, in which text may be}
  4. {    typed and standard Cut/Copy/Paste/Clear operations may be performed.}
  5. {    Undo is not supported, nor is text scrolling.}
  6.  
  7. {    14 June 1986        Paul DuBois}
  8. {    7 January 1987    Owen Hartnett    }
  9.  
  10. UNIT MultiSkelEdit;
  11.  
  12. INTERFACE
  13.  
  14.     USES
  15.         MultiSkelGlobs, common, TransSkelpas;
  16.  
  17.     PROCEDURE EditWindInit;
  18.     PROCEDURE EditWindEditMenu (item : integer);
  19.  
  20.  
  21. IMPLEMENTATION
  22. { edit menu item numbers }
  23.  
  24.     CONST
  25.         undo = 1;
  26.         cut = 3;
  27.         copy = 4;
  28.         paste = 5;
  29.         clear = 6;
  30.  
  31.     VAR
  32.         teEdit : TEHandle;        { handle to text window TextEdit record }
  33.  
  34.     PROCEDURE Halt;
  35.  
  36.     BEGIN
  37.         TEDispose(teEdit);
  38.         CloseWindow(editWind);
  39.     END;
  40.  
  41.     PROCEDURE Idle;
  42.  
  43.     BEGIN
  44.         TEIdle(teEdit);    { blink that cursor! }
  45.     END;
  46.  
  47.     PROCEDURE key (ch : char;
  48.                                     mods : integer);
  49.  
  50.     BEGIN
  51.         TEKey(ch, teEdit);
  52.     END;
  53.  
  54.  
  55.     PROCEDURE Mouse (thePt : Point;
  56.                                     t : longint;
  57.                                     mods : integer);
  58.     BEGIN
  59.         TEClick(thePt, Boolean(BitAnd(mods, shiftKey)), teEdit);
  60.     END;
  61.  
  62. {    Update text window.  The update event might be in response to a}
  63. {    window resizing.  If so, resize the rects and recalc the linestarts}
  64. {    of the text.  To resize the rects, only the right edge of the}
  65. {    destRect need be changed (the bottom is not used, and the left and}
  66. {    top should not be changed). The viewRect should be sized to the}
  67. {    screen.}
  68.  
  69.     PROCEDURE Update (resized : Boolean);
  70.  
  71.         VAR
  72.             r : Rect;
  73.  
  74.     BEGIN
  75.         r := editWind^.portRect;
  76.         EraseRect(r);
  77.         r.left := r.left + 4;
  78.         r.bottom := r.bottom - 2;
  79.         r.top := r.top + 2;
  80.         r.right := r.right + 19;
  81.         IF resized THEN
  82.             BEGIN
  83.                 teEdit^^.destRect.right := r.right;
  84.                 teEdit^^.viewRect := r;
  85.                 TECalText(teEdit);
  86.             END;
  87.         DrawGrowBox(editWind);
  88.         TEUpdate(r, teEdit);
  89.     END;
  90.  
  91.     PROCEDURE Activate (active : Boolean);
  92.  
  93.     BEGIN
  94.         DrawGrowBox(editWind);
  95.         IF active THEN
  96.             BEGIN
  97.                 TEActivate(teEdit);
  98.                 DisableItem(editMenu, undo);
  99.             END
  100.         ELSE
  101.             BEGIN
  102.                 TEDeactivate(teEdit);
  103.                 EnableItem(editMenu, undo);
  104.             END;
  105.     END;
  106.  
  107. {    Handle Edit menu items for text window}
  108.  
  109.     PROCEDURE EditWindEditMenu;
  110.  
  111.         VAR
  112.             ignore : integer;
  113.     BEGIN
  114.         CASE item OF
  115.             cut : 
  116.  
  117. {    cut selection, put in TE Scrap, clear clipboard and put}
  118. {    TE scrap in it}
  119.  
  120.                 BEGIN
  121.                     TECut(teEdit);
  122.                     ignore := ZeroScrap;
  123.                     ignore := TEToScrap;
  124.                 END;
  125.             copy : 
  126.  
  127. {    copy selection to TE Scrap, clear clipboard and put}
  128. {    TE scrap in it}
  129.  
  130.                 BEGIN
  131.                     TECopy(teEdit);
  132.                     ignore := zeroscrap;
  133.                     ignore := TEToScrap;
  134.                 END;
  135.             paste : 
  136.  
  137. {    get clipboard into TE scrap, put TE scrap into edit record}
  138.  
  139.                 BEGIN
  140.                     ignore := TEFromScrap;
  141.                     TEPaste(teEdit);
  142.                 END;
  143.             clear : 
  144.  
  145. {    delete selection without putting into TE scrap or clipboard}
  146.  
  147.                 TEDelete(teEdit);
  148.             OTHERWISE
  149.                 ;
  150.         END;
  151.     END;
  152.  
  153.     PROCEDURE EditWindInit;
  154.         VAR
  155.             r : Rect;
  156.             str : str255;
  157.             kludge : longint;
  158.             strptr : Ptr;
  159.  
  160.     BEGIN
  161.         editWind := GetNewWindow(editWindRes, NIL, WindowPtr(-1));
  162.         SkelWindow(editWind, @Mouse, @Key, @Update, @Activate, NIL, @Halt, @Idle, true);
  163.         TextFont(0);
  164.         TextSize(0);
  165.         r := editWind^.portRect;
  166.         r.left := r.left + 4;
  167.         r.bottom := r.bottom - 2;
  168.         r.top := r.top + 2;
  169.         r.right := r.right - 19;
  170.         teEdit := TENew(r, r);
  171.         str := 'This is the text editing window.';
  172.         strPtr := @str;
  173.         kludge := longint(strPtr) + 1;
  174.         strPtr := Ptr(kludge);
  175.         TEInsert(strPtr, longint(str[0]), teEdit);
  176.     END;
  177. END.